import java.awt.Color;
import java.awt.Font;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.Random;
import java.util.ResourceBundle;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.aqarat.controller.AqaratControllerImpl;
import com.aqarat.entity.resultsetmapping.PaymentResultSet;
import com.common.Constant;

public class Run {

	/**
	 * @param args
	 */
	public static final String SMTP_HOST_NAME = "smtp.gmail.com";
	public static final int SMTP_HOST_PORT = 465;
	public static final String SMTP_AUTH_USER = "test56228@gmail.com";
	public static final String SMTP_AUTH_PWD = "k37458266";

	public static void main(String[] args) throws Exception {
		
		
//		AqaratControllerImpl aqaratController = new AqaratControllerImpl();
//
//		Date expenscurentDate = new Date();
//		DateFormat expensformatterFrom = new SimpleDateFormat("dd/MM/yyyy");
//		Date dateFrom = expensformatterFrom.parse("26/11/2012");
//
//		DateFormat expensformatterTo = new SimpleDateFormat("dd/MM/yyyy");
//		Date dateTo = expensformatterTo.parse("30/11/2012");

		// DateFormat expensformatter = new SimpleDateFormat("dd/MM/yyyy");
		// Date expensDate = expensformatter.parse("27/11/2012");

//		Expens ex = new Expens();
//		ex.setDateFrom(dateFrom);
//		ex.setDateTo(dateTo);
//		List<Expens> exl = aqaratController.getExpensList(1, 10, null, null, null, ex);
//		for (Expens exx : exl) {
//			System.out.println(exx);
//		}
		// ==========================================================================//

		// List<Building> bl=aqaratController.getBuildingLookupList();
		// System.out.println(bl.size());
		// for(Building b:bl){
		// System.out.println(b);
		// }

		// ==========================================================================//
//		AqaratControllerImpl aqaratController__ = new AqaratControllerImpl();
//		 Date curentDate = new Date();
//		 DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
//		 Date dateFrom = formatter.parse("01/01/2013");
//		
//		 DateFormat formatter2 = new SimpleDateFormat("dd/MM/yyyy");
//		 Date dateTwo = formatter2.parse("30/01/2013");
//		
//		 PaymentResultSet prs=new PaymentResultSet();
//		 // prs.setCustomerId(2L);
//		 prs.setPaymentDate(new Date());
//		 prs.setDateFrom(dateFrom);
//		 prs.setDateTo(dateTwo);
//		
//		 List<PaymentResultSet>
//		 pl=aqaratController__.getPaymentResultSetList(prs);
//		 System.out.println(pl.size());
//		 for(PaymentResultSet prss:pl){
//		 System.out.println(prss);
//		 }
		 System.out.println("==============================================================================");
//		AqaratControllerImpl aqaratController_ = new AqaratControllerImpl();
//
//		Date expenscurentDate = new Date();
//		DateFormat expensformatterFrom = new SimpleDateFormat("dd/MM/yyyy");
//		Date dateFrom = expensformatterFrom.parse("20/01/2013");
//
//		DateFormat expensformatterTo = new SimpleDateFormat("dd/MM/yyyy");
//		Date dateTo = expensformatterTo.parse("30/01/2013");
//		
//		 Payment p=new Payment();
//		 p.setPaymentDate(new Date());
//		 p.setDateFrom(dateFrom);
//		 p.setDateTo(dateTo);
//		 List<Payment> pll=aqaratController.getPaymentList(p);
//		 System.out.println(pll.size());
//		 for(Payment prss:pll){
//		 System.out.println(prss);
//		 }
		// ================================================================//
		// List<Date>dl= Utils.getDateList(new Date(), 4);
		// for(Date d:dl){
		// System.out.println(Utils.formatDateTimeAsDate(d));
		// }
		// ===================================================================//
		// Date curentDate = new Date();
		// System.out.println(curentDate.toString());
		// System.out.println((new Date()).toString());
		//
		// System.out
		// .println("formated >> " + Utils.formatDateTime(curentDate));
		// System.out.println("not formated >> "
		// + Utils.formatDateTimeAsDate(curentDate));
		//
		// Calendar cal = Calendar.getInstance();
		// cal.setTime(Utils.formatDateTimeAsDate(new Date()));
		// cal.add(Calendar.MONTH, 1);
		// System.out.println(cal.getTime());
		//
		// System.out.println("------------");
		// DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
		//
		// Date date = formatter.parse(Utils.formatDateTime(curentDate));
		// System.out.println("== "+Utils.formatDateTime(date));
		// Calendar call = Calendar.getInstance();
		// call.setTime(date);
		// call.add(Calendar.MONTH, 1);
		// System.out.println(call.getTime());
		//
		// for(int i=1;i<=10;i++){
		// call.add(Calendar.MONTH, 1);
		// System.out.println(Utils.formatDateTime(call.getTime()));
		// }

		// ==================================================================//

		// AqaratController aqaratController = new AqaratControllerImpl();
		// List<Floor> fl=aqaratController.getFloorListByBuildingId(7L);
		// System.out.println(fl.size());

		// List<Customer> cl=aqaratController.getCustomerList(null);
		// System.out.println(cl.size());
		// ========================================//
		// Building bbb=new Building();
		// bbb.setRecid(7L);
		// bbb.setName("awda");
		// List<Building>bl= aqaratController.getBuildingList(bbb);
		// System.out.println(bl.size());
		// ========================================//
		// Building bb=new Building();
		// bb.setRecid(7L);
		// Floor f=new Floor();
		// f.setNo(1L);
		// f.setBuilding(new Building(7L));
		// Apartment a=new Apartment();
		// a.setNo(1L);
		// a.setFloor(f);
		//
		// List<Apartment>ll=aqaratController.getApartmentList(a);
		// System.out.println(ll.size());
		// System.out.println(ll.get(0).toString());

		// Building b = new Building();
		// b.setAddress("manshia4");
		// b.setNumberOfFloors(4L);
		// b.setName("Rawda4");
		//
		// Floor f = new Floor();
		// f.setNumberOfApartments(4L);
		//
		// List<Apartment> apartmentList = new ArrayList<Apartment>();
		// Apartment a1 = new Apartment();
		// a1.setArea(110D);
		// Apartment a2 = new Apartment();
		// a2.setArea(120D);
		// Apartment a3 = new Apartment();
		// a3.setArea(130D);
		// Apartment a4 = new Apartment();
		// a4.setArea(140D);
		// apartmentList.add(a1);
		// apartmentList.add(a2);
		// apartmentList.add(a3);
		// apartmentList.add(a4);
		//
		// aqaratController.saveBuilding(b, f, apartmentList);
		//
		// System.out.println(b);
		// System.out.println("welcom");

		// List<GroupPrivilege> df=ad.getAllGroupPrivileges(1L);
		// System.out.println(df.size());
		// ad.deleteAllGroupPrivilegesOfGroup(100L);
		// System.out.println("succ");
		// System.out.println(Utils.md5pwd("admin",null));
		// System.out.println(Utils.md5pwd("admin",""));
		// System.out.println(Utils.md5pwd("admin", "Anabib#@systeM"));
		// System.out.println(Utils.md5pwd("admin", "Anabib"));

		// AnabibDaoImpl controller =new AnabibDaoImpl ();
		// List<AreaMapping> ff=controller.getListAreaMapping();
		// System.out.println(ff.size());
		// System.out.println("--------------------------------------------------");
		// System.out.println("all responsibles         "+controller.getAllResponsiblesCount());
		// System.out.println("all responsibles in area "+controller.getResponsiblesCountOfArea(3L));
		// try {
		// Mail m=new Mail("","test56228@gmail.com", "test mail from java",
		// "this is a test mail from java");
		// m.sendEmail() ;
		// System.out.println("succ sending");
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		// draow();
		// DrawingwithAGradientColor();
		// System.out.println(new Random().nextInt(50));

		// getNm();
		// System.out.println("Random Number : " + getNm());
		// Controller controller =new Controller ();
		// List<Member> dd=controller.getListMember("%fg%");
		// System.out.println(dd.size());
		// Controller controller =new Controller ();
		// List<MemberMapping> l=controller.getAllMembersMapping();
		// MemberMapping mm=(MemberMapping)l.get(0);
		// System.out.println(mm);

		// -----------------------------//
		// Long l=controller.getRowCount();
		// System.out.println("......... "+controller.getRowCount());
		// Controller controller =new Controller ();
		// List<AnabibAverage> avv=controller.getListAnabibAverag();
		// System.out.println(avv.size());
		// ==================================================================================//

		 Locale locale = Locale.getDefault();
		 // System.out.println(Locale.getAvailableLocales());
//		 String karim ="كريم";
//		 Locale d=new Locale("ar");
		 // System.out.println(locale.getLanguage());
		 try {
		 ResourceBundle resource =
		 ResourceBundle.getBundle("com.manshia.bundle.administration.messages",locale);
		 String value=resource.getString("Administration_General_Close");
		 System.out.println(value);

//		 FacesMessage fmsg = MessageFactory.getMessage("Anabib_Public_Error");
//		 String s=fmsg.getSummary();
//		 System.out.println(s +"==");
		 } catch (java.util.MissingResourceException e) {
		 System.out.println("--");
		 }
//		 System.out.println(karim);

		// ====================================================================================//
		// Controller controller =new Controller ();
		// Long ll=controller.getAllAreasCount();
		// System.out.println("--Hibernate: select count(distinct area0_.recid) as col_0_0_ from area area0_");
		// ====================================================================================//
		// Controller controller =new Controller ();
		// Long ll=controller.getAllAreasCount();
		// System.out.println("--Hibernate: select count(distinct area0_.recid) as col_0_0_ from area area0_");
	}

	public static void getNm() {
		Random r = new Random();
		int no = 0;
		// Check result between 1 to 50
		while (no < 10) {
			no = r.nextInt(50);
		}

		System.out.println("Random Number : " + no);

	}

	private static int getRandomNumber(int max) {
		Random ran = new Random();
		return 1 + ran.nextInt(max);
	}

	public static void send() throws Exception {
		Properties props = new Properties();

		props.put("mail.transport.protocol", Constant.PROTOCOL);
		props.put("mail.smtps.host", SMTP_HOST_NAME);
		props.put("mail.smtps.auth", "true");

		Session mailSession = Session.getDefaultInstance(props);
		mailSession.setDebug(true);
		Transport transport = mailSession.getTransport();

		MimeMessage message = new MimeMessage(mailSession);
		message.setSubject("Testing SMTP-SSL from java");
		message.setContent("This is a test", "text/plain");

		message.addRecipient(Message.RecipientType.TO, new InternetAddress("test56228@gmail.com"));

		transport.connect(SMTP_HOST_NAME, SMTP_HOST_PORT, SMTP_AUTH_USER, SMTP_AUTH_PWD);

		transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
		transport.close();
	}

	public static void draow() {

		JFrame f = new JFrame("Gradient Background Demo");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel contentPane = new JPanel() {
			/**
			 * 
			 */

			@Override
			protected void paintComponent(Graphics grphcs) {
				Graphics2D g2d = (Graphics2D) grphcs;
				// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);

				int height = 35;
				int width = 100;

				// BufferedImage image = new BufferedImage(width, height,
				// BufferedImage.TYPE_INT_RGB);
				// Graphics2D graphics2D = image.createGraphics();
				// Hashtable map = new Hashtable();
				Random r = new Random();
				String token = Long.toString(Math.abs(r.nextLong()), 36);
				String ch = token.substring(0, 6);
				// Color c = new Color(0.6662f, 0.4569f, 0.3232f);
				GradientPaint gp = new GradientPaint(30, 30, Color.red, 15, 25, Color.BLUE, true);
				g2d.setPaint(gp);
				g2d.setBackground(Color.blue);
				Font font = new Font("Verdana", Font.CENTER_BASELINE, 20);
				g2d.setFont(font);
				g2d.drawString(ch, 2, 20);
				g2d.dispose();

				super.paintComponent(grphcs);
			}
		};
		contentPane.setOpaque(false);
		f.setContentPane(contentPane);
		// ImageIcon icon = new
		// ImageIcon(GradientBackgroundDemo.class.getResource("gears.png"));
		contentPane.add(new JLabel("test"));
		f.setSize(200, 200);
		f.setVisible(true);
	}

	public static void DrawingwithAGradientColor() {
		JFrame f = new JFrame("Gradient Background Demo");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel contentPane = new JPanel() {
			@Override
			protected void paintComponent(Graphics grphcs) {
				Graphics2D g2d = (Graphics2D) grphcs;

				// Color startColor = Color.red;
				// Color endColor = Color.blue;

				// A non-cyclic gradient
				GradientPaint gp = new GradientPaint(50, 10, getBackground().green, 2, getHeight(), getBackground().red);
				g2d.setPaint(gp);
				g2d.fillRect(0, 0, getWidth(), getHeight());

				g2d.rotate(Math.toRadians(10));
				g2d.drawString("hiiiiiiiiiii", 0, 0);

				// g2d.drawLine((int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));
				// g2d.drawOval((int) (Math.random()*100),(int)
				// (Math.random()*100), (int) (Math.random()*100),(int)
				// (Math.random()*100));
				// g2d.drawRect((int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));

				// int startAngle = 45;
				// int arcAngle = -60;
				// g2d.drawArc((int) (Math.random()*100), (int)
				// (Math.random()*100),(int) (Math.random()*100), (int)
				// (Math.random()*100), startAngle, arcAngle);
				//
				// g2d.drawRoundRect((int) (Math.random()*100),(int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));
			}
		};
		contentPane.setOpaque(false);
		f.setContentPane(contentPane);
		// ImageIcon icon = new
		// ImageIcon(GradientBackgroundDemo.class.getResource("gears.png"));
		contentPane.add(new JLabel("test"));
		f.setSize(200, 200);
		f.setVisible(true);
	}

	public static void sd() {
		JFrame f = new JFrame("Gradient Background Demo");
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		JPanel contentPane = new JPanel() {
			@Override
			protected void paintComponent(Graphics grphcs) {
				Graphics2D g2d = (Graphics2D) grphcs;

				// Color startColor = Color.red;
				// Color endColor = Color.blue;

				// A non-cyclic gradient
				GradientPaint gp = new GradientPaint(50, 10, getBackground().green, 2, getHeight(), getBackground().red);
				g2d.setPaint(gp);
				g2d.fillRect(0, 0, getWidth(), getHeight());

				g2d.rotate(Math.toRadians(10));
				g2d.drawString("hiiiiiiiiiii", 0, 0);

				// g2d.drawLine((int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));
				// g2d.drawOval((int) (Math.random()*100),(int)
				// (Math.random()*100), (int) (Math.random()*100),(int)
				// (Math.random()*100));
				// g2d.drawRect((int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));

				// int startAngle = 45;
				// int arcAngle = -60;
				// g2d.drawArc((int) (Math.random()*100), (int)
				// (Math.random()*100),(int) (Math.random()*100), (int)
				// (Math.random()*100), startAngle, arcAngle);
				//
				// g2d.drawRoundRect((int) (Math.random()*100),(int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100), (int) (Math.random()*100), (int)
				// (Math.random()*100));
			}
		};
		contentPane.setOpaque(false);
		f.setContentPane(contentPane);
		// ImageIcon icon = new
		// ImageIcon(GradientBackgroundDemo.class.getResource("gears.png"));
		contentPane.add(new JLabel("test"));
		f.setSize(200, 200);
		f.setVisible(true);

	}
}